package cn.bytecollege.controller;

import cn.bytecollege.model.Goods;
import cn.bytecollege.service.SystemService;
import cn.bytecollege.vo.CommunityWorkerVO;
import cn.bytecollege.vo.DistributionWorkerVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
//@RestController
@RequestMapping("/system")
@Log
public class SystemController {
    @Autowired
    private SystemService systemService;

    /**
     * 查询社区人员信息
     * @return
     */
    @GetMapping("/communityWorkerList")
    public String communityWorkerList(Model model){
        List<CommunityWorkerVO> list = systemService.getCommunityWorker();
        model.addAttribute("communityWorkerList",list);
        return "system/communityWorkerList";
    }
    /**
     * 删除社区人员
     */
    @GetMapping("/delCommunityWorker")
    public String delCommunityWorker(Integer id){
        systemService.delCommunityWorker(id);
        return "redirect:/system/communityWorkerList";
    }
    /**
     * 更新社区人员信息
     */
    @GetMapping("/modCommunityWorker")
    public  String modCommunityWorker(Integer id ,Model  model){
        CommunityWorkerVO communityWorkerVO = systemService.getCommunityWorker(id);
        model.addAttribute("communityWorkerVO",communityWorkerVO);
        return "/system/modCommunityWorker";
    }
    @PostMapping("/modCommunityWorker")
    public  String modCommunityWorker(CommunityWorkerVO communityWorkerVO){
        systemService.modCommunityWorker(communityWorkerVO);
        return "redirect:/system/communityWorkerList";
    }
    /**
     * 添加社区人员
     */
    @GetMapping("/addCommunityWorker")
    public String addCommunityWorker(){
        return "system/addCommunityWorker";
    }
    @PostMapping("/addCommunityWorker")
    public String addCommunityWorker(CommunityWorkerVO communityWorkerVO){
        systemService.addCommunityWorker(communityWorkerVO);
        return "redirect:/system/communityWorkerList";
    }

    /**
     * 通过用户名查询
     * @param username
     * @return
     */
    @GetMapping("/findByCommunityWorkerName")
    public String findByCommunityWorkerName(String username,Model model){
        List<CommunityWorkerVO> list = systemService.findByCommunityWorkerName(username);
        model.addAttribute("communityWorkerList",list);
        return "/system/communityWorkerList";
    }


    /**
     * 查询配送人员信息
     * @return
     */
    @GetMapping("/getDistributionWorker")
    public List<DistributionWorkerVO> getDistributionWorker(){
        return systemService.getDistributionWorker();
    }
    @GetMapping("/distributionWorkerList")
    public String distributionWorkerList(Model model){
        List<DistributionWorkerVO> list = systemService.getDistributionWorker();
        model.addAttribute("distributionWorkerList",list);
        return "system/distributionWorkerList";
    }
    /**
     * 删除配送人员
     */
    @GetMapping("/delDistributionWorker")
    public String delDistributionWorker(Integer id){
        systemService.delCommunityWorker(id);
        return "redirect:/system/distributionWorkerList";
    }
    /**
     * 更新配送人员信息
     */
    @GetMapping("/modDistributionWorker")
    public  String modDistributionWorker(Integer id ,Model  model){
        DistributionWorkerVO distributionWorkerVO = systemService.getDistributionWorker(id);
        model.addAttribute("distributionWorkerVO",distributionWorkerVO);
        return "/system/modDistributionWorker";
    }
    @PostMapping("/modDistributionWorker")
    public  String modDistributionWorker(DistributionWorkerVO distributionWorkerVO){
        systemService.modDistributionWorker(distributionWorkerVO);
        return "redirect:/system/distributionWorkerList";
    }
    /**
     * 添加配送人员
     */
    @GetMapping("/addDistributionWorker")
    public String addDistributionWorker(){
        return "system/addDistributionWorker";
    }
    @PostMapping("/addDistributionWorker")
    public String addDistributionWorker(DistributionWorkerVO distributionWorkerVO){
        systemService.addDistributionWorker(distributionWorkerVO);
        return "redirect:/system/distributionWorkerList";
    }
    /**
     * 通过姓名查询
     */
    @GetMapping("/findByDistributionWorkerName")
    public String findByDistributionWorkerName(String username,Model model){
        List<DistributionWorkerVO> list = systemService.findByDistributionWorkerName(username);
        model.addAttribute("distributionWorkerList",list);
        return "/system/distributionWorkerList";
    }
}